<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>账号管理</title>
    <link rel="shortcut icon" href="/images/index/logo.ico">
    <style>
        .refresh {
            display: inline-block;
            float: right;
        }
    </style>
</head>
<body>
<%--javascript:location.replace(location.href);--%>
<div class="refresh">
    <button class="btn btn-info search" title="刷新" data-url="/accountAdmin/admin/list"><span
            class="glyphicon glyphicon-refresh"></span></button>
</div>
<div class="" style="margin-bottom: 65px;">
    <ol class="breadcrumb">
        <li><a href="javascript:;">账号管理</a></li>
        <li class="active">账号查看和管理</li>
    </ol>
</div>
<div class="account_table">
    <table class="table table-bordered table-responsive ">
        <tr>
            <th>id</th>
            <th>账号</th>
            <th>邮箱</th>
            <th>手机号码</th>
            <th>类型</th>
            <th>账号状态</th>
            <th>操作</th>
        </tr>
        <c:forEach var="data" items="${dataMap}">
            <tr>
                <td class="id">${data.id}</td>
                <td>${data.username}</td>
                <td>${data.email}</td>
                <td>${data.phone}</td>
                <td><c:if test="${data.types==2}">普通用户</c:if><c:if test="${data.types==1}">管理员</c:if></td>
                <td><c:if test="${data.state}">正常</c:if><c:if test="${data.state==false}">未启用</c:if></td>
                <td class="">
                    <button class=" btn btn-info start_stop" data-state="${data.state}"><c:if
                            test="${data.state}">禁用</c:if><c:if
                            test="${data.state==false}">启用</c:if></button>
                    <button class="btn btn-danger delete" onclick="deleteAccount(this,'${data.id}')">删除</button>
                </td>
            </tr>
        </c:forEach>
    </table>
</div>
<button class="btn btn-info add" data-url="<%=basePath%>accountAdmin/admin/addinput">
    <span class="glyphicon glyphicon-plus"></span> 添加
</button>
<script>
    function deleteAccount(obj, id) {
        custom_modal('你确定要删除么？')
        $('.modal_footer button').eq(0).unbind().click(function () {
            $.post("<%=basePath%>accountAdmin/admin/delete", {id: id}, function (data) {
                if (data.code == 200) {
                    $(obj).parents("tr").remove();
                }
                $('.modal_1').fadeOut();
                toast_text(data.msg, 600);
            })
        });

    }

    function custom_modal(content) {
        $('.modal_content').text(content);
        $('.modal_1').fadeIn();
    }

    $(document).ready(function () {
        $('.add').click(function () {
            var scope = $(this);
            $('.content_right').load(scope.attr('data-url'));
        });
        $('.search').click(function () {
            var scope = $(this);
            $('.content_right').load(scope.attr('data-url'));
            toast_text('刷新成功', 600);
        });
        $('.start_stop').unbind().click(function () {
            var scope = $(this);
            start_top('/accountAdmin/admin/change', $(this).parent().siblings('.id').text(), $(this).attr('data-state'), '/accountAdmin/admin/list');
        });

    });
</script>
</body>
</html>